<template>
  <div class="box">
    <img
      src="https://scpic.chinaz.net/files/pic/pic9/202003/zzpic23514.jpg"
      alt=""
    />
    <p @click="changeColor" :style="{ backgroundColor: bgColor }">这是个博美</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      bgColor: "",
    };
  },
  methods: {
    changeColor() {
      this.bgColor = `rgb(${Math.floor(Math.random() * 256)},${Math.floor(
        Math.random() * 256
      )},${Math.floor(Math.random() * 256)})`;
    },
  },
};
</script>

<style lang="less" scoped>
div {
  width: 300px;
  // width: 50%;
  border: 2px solid #ccc;
  text-align: center;
  float: left;
  img {
    width: 100%;
  }
}
</style>
